﻿#ifndef NSA3000TPFUN_H
#define NSA3000TPFUN_H

#include <QtCore/qglobal.h>

#include "sys_h/SYS_VER.h"
#include "sys_h/DATATYPE.h"
#include "sys_h/DATATYPE_S.h"
#include "db_h/TABLEDEF.h"
#include "sys_h/SYS_DATA.h"
#include "order_h/NET_ORDER_NUM.h"
#include "order_h/DATA_ORDER_NUM.h"
#include "seq_define.h"
#include "CWFDefine.h"
#include "hTableDef.h"
#include "NSA3000TDB.h"


#if defined(NSA3000TPFUN_LIBRARY)
#  define NSA3000TPFUNSHARED_EXPORT Q_DECL_EXPORT
#else
#  define NSA3000TPFUNSHARED_EXPORT Q_DECL_IMPORT
#endif

class NSA3000TPFUNSHARED_EXPORT NSA3000TPFUN 
{
public:
    NSA3000TPFUN();

	XINT Init_pfun_dll(NSA3000TDB* db);
	void Free_pfun_dll();
	XINT GetSysparaTable(rParam_System &para_record);

	//厂站
	XINT GetAllRtuInfo(rRtu_Info*& pRet, XINT  &nCount);

    //节点
	XINT GetRNODEInfo(rNode_Info*& pRet,XINT  &nCount);
	XINT GetDevStateInfoByDevID(rDevRunStateDefine_Info*& pRet,XINT  &nCount);


	//设备
	XINT GetDevRecordByDevByName(char* DevByName,rDevice_Info& Dev);
	XINT GetDevIDByDevByName(char* DevByName,XINT& DevID);
	XINT GetDevRecordByDevid(int devid,rDevice_Info& Dev);
	XINT GetDevRecordByDevAdd(int devadd,rDevice_Info& Dev);
	XINT GetCurDevByNamebyID(XINT DevID,QString &DevByName);
	XINT GetCurDevNamebyID(XINT DevID,QString &DevName);     

    //五遥
	XINT GetYXRecordByDBlink(DATA_LINK link,rYxDefine_Info &yxrecord);
	XINT GetYCRecordByDBlink(DATA_LINK link,rYcDefine_Info &yxrecord);
	XINT GetYKRecordByDBlink(DATA_LINK link,rYkDefine_Info &yxrecord);
	XINT GetYKRecordByYxDBlink(DATA_LINK link,rYkDefine_Info &ykrecord);

    XINT GetYXRecordByYxID(XINT yxid,rYxDefine_Info &yxrecord);

	XINT  GetDevInfoByRtuID(XINT RtuID,rDevice_Info*& pRet, XINT &nCount);
	XINT  GetYXInfoByDevID(XINT DevID,rYxDefine_Info*& pRet, XINT &nCount);
	XINT  GetYCInfoByDevID(XINT DevID,rYcDefine_Info*& pRet, XINT &nCount);
	XINT  GetYKInfoByDevID(XINT DevID,rYkDefine_Info*& pRet, XINT &nCount);
	XINT  GetYMInfoByDevID(XINT DevID,rYmDefine_Info*& pRet, XINT &nCount);
	XINT  GetYTInfoByDevID(XINT DevID,rYtDefine_Info*& pRet, XINT &nCount);


	//五防
	XINT GetWFYxAll(rWf_Yx_Info *&pwf_parem_yx,XINT &nCount);
	XINT GetWFYcAll(rWf_Yc_Info *&pwf_parem_yc,XINT &nCount);
	XINT GetWFYXRecordByID(XINT ID,rWf_Yx_Info &wf_parem_yx);
	XBOOL8 GetWFFullNameByParentByNameAndIndex(QString sDevByName,XINT index,XINT TableID,QString& sFullName);
	XINT GetWFYXTypeByParentByNameandindex(QString sParentByName,XINT index);
	XINT GetWfYxByDBLink(DATA_LINK db_link,rWf_Yx_Info &wf_parem_yx);
	XINT GetWfYxByLock_Add(XINT Lock_Add,rWf_Yx_Info &wf_parem_yx);
	XINT GetWFYXIndexNameandTypeByDevByNameAndindex(char *szByName,XINT ParentIndex,char *szIndexName,XINT &WFType);
	XINT  GetWfYcByDBLink(DATA_LINK db_link,rWf_Yc_Info &wf_parem_yc);
	XINT  GetWFYXRecordByIndexName(QString sIndexName,rWf_Yx_Info &wf_parem_yx);
	XINT  GetWFYCRecordByID(XINT ID,rWf_Yc_Info &wf_parem_yc);
	XINT GetALLWFYXIndexName(WF_PARAM_YX_INDEX*& pRet,XINT& nCount);
	XINT GetALLWFYCIndexName(WF_PARAM_YC_INDEX*& pRet,XINT& nCount);
	XINT  GetWfDevNamebyType(XINT Type,QString& DevName);
	XINT  GetWfDevIDbyName(QString sName,XINT& DevID);
	XINT  GetWFDeviceType(rWf_DevType *&pwf_Dev_type,XINT &count);
	XINT  GetWfSimpleYxByRtuIDAndType(XINT Type,WF_PARAM_YX_SIMPLE *&pRet,XINT& nCount);


	//五防间隔
	XINT GetMainUnitStruct(rWf_Unit_Info *&wf_param_unit,XINT &count);
	XINT GetWfParamUnitInfoByVoltage(rWf_Unit_Info *&pwf_param_unit,XINT &count,XINT rtu_id,XINT ParentID);
	XINT GetUnitStruct_by_devid(XINT dev_id,rWf_Unit_Info &wf_param_unit,int &ncount);
	XINT GetUnitStruct_by_unitid(XINT unitid,rWf_Unit_Info &wf_param_unit,int &ncount);
	XINT GetWfChildUnitInfobyRtuID(rWf_Unit_Info *&pwf_param_unit,XINT &count,XINT rtu_id);
	XINT GetWFYXRecordBySubUNit(XINT Subuint,rWf_Yx_Info *&pwf_parem_yx,XINT &nCount);
	XUCHAR GetWFOperTypeByWFYxType(XINT wf_type);
	XINT   GetWFUnit(rWf_Unit_Info*& pRet,XINT  &nCount);
	XINT WriteUnitRecord(rWf_Unit_Info wf_param_unit);
	XINT GetWfUnitInfobyUnitID(rWf_Unit_Info &pwf_param_unit,XINT unit_id);


	
	XINT GetWf_para_record(rWf_Set_Para &record);

	//五防短语
	XINT GetWfCommOper(rWf_CommOperPhrase *&pwf_param_comm_oper,XINT &count);
	XINT GetWfCommOper(XINT type_id,XCHAR start_state,XCHAR end_state,rWf_CommOperPhrase &wf_param_comm_oper);
	XINT GetWfCommOper_devType(XINT type_id, rWf_CommOperPhrase *&wf_param_comm_oper,XINT &count);
	XINT GetCommonPrompt(rWf_CommPromptPhrase *&comm_prompt,XINT &count);
	XINT GetCommonPrompt(DATA_LINK db_link,XINT type_id,XINT start_state,XINT end_state,rWf_CommPromptPhrase *&comm_prompt,XINT &count,XCHAR type);
	QString GetOperStringOrPrompt(QString sFormat,char *sVerb,DATA_LINK db_link);


	//票库通用函数
	XINT  DeleteWFTicket_ALL(XUCHAR DB_Type);
	XINT  DeleteWFTicket_by_unitid_seqtype(XUCHAR DB_Type,int unitid,int seqtype);
	XINT  fnWriteWFTicketIndexTable(hwf_ticket_index_table &pWrite, XUCHAR DB_Type);
	XINT  fnReadWFTicketTaskContentByTicketID(hwf_ticket_task_content *&pList,XINT &nCount,XINT task_id,XUCHAR DB_Type);
	XINT  fnReadWFTicketIndexTableByID(hwf_ticket_index_table &ticket_index,XINT ticket_id,XUCHAR DB_Type);
	XINT  fnGetWFTicketMAXID(XUCHAR DB_Type);
	XINT  fnDeleteTicketByID(XINT ticket_id,XUCHAR DB_Type);
	XINT  fnGetWFTicketMAXContentID(XBYTE DB_Type);
	XINT  fnWriteWFTicketTaskContent(hwf_ticket_task_content &pWrite, XUCHAR DB_Type);
	XBOOL8  WriteContent(LIST_Wf_Ticket g_wf_ticket ,  XUCHAR DB_Type,int ticketid);
	
	XINT  GetTicketInfByTicketTypeandUnitID(hwf_ticket_index_table *&pTicketInfo,XUCHAR DB_Type,XINT &count,XINT UnitID);
	XINT  NSA3000TModifyDB(XCHAR* sql);

	//历史库查询
	XINT  Get5Y_simple_InfoByDevID(XINT tableType,XINT DevID,rYxDefine_Connect*& pRet, XINT &nCount);
	XINT  Get5Y_RecordByDevID_form_RealDB(XINT tableType,XUINT DevID,char*& pRet, XINT &nCount);
	XINT   GetDevInfoByRtuID_from_RealDB(XINT  RtuID,rDevice_Info*& pRet, XINT  &nCount);
	XBOOL8  GetCurYCRecByYCID(XINT ID,rYcDefine_Info& sycrecord);
	XBOOL8  GetCurYMRecByYMID(XINT ID,rYmDefine_Info& symrecord);
	QString GetQuXianDataUnit(XINT unit);



	//五防规则
	void  CheckRule_Perline(QString line);
	XINT  GetRuleListBy_DevByName_IndexNo(XCHAR *szByName,XINT ParentIndex,rWf_Rule_Info*& pIndex,XINT& nCount);
	XINT  WriteRuleRecord(rWf_Rule_Info pRule);
	XINT  DeleteRuleByDevbyname_Indexno(char *DevByname,int indexno);




	//五防通用表
	XINT  DeleteWf_DevTable();
	XINT  DeleteWf_DevRecord(XINT wfdev_type);
	XINT  DeleteComm_OperTable();
	XINT  DeleteComm_OperTable_by_devtype(int dev_type);
	XINT  DeleteComm_PromptTable();
	XINT  DeleteComm_PromptTable_by_devtype(int dev_type);
	XINT  DeleteSpecialPromptRecord_by_dblink_startState_endState_prompttype(DATA_LINK db_link,int StartState,int EndState,int PromptType);
	XINT  DeleteCommPromptRecord_by_DevType_startState_endState_prompttype(int WfDevType,int StartState,int EndState,int PromptType);

	XINT  DeleteLink_by_dblink_startState_endState(DATA_LINK db_link,int StartState,int EndState,int pre_or_after);

	XINT  Writewf_devRecord(rWf_DevType pRule);
	XINT  Writecomm_operRecord(rWf_CommOperPhrase pRule);
	XINT  Writecomm_promptRecord(rWf_CommPromptPhrase pRule);

	XINT  WriteSpecial_promptRecord(rWf_SpecialPromptPhrase pRule);
	XINT  WriteWfOperateRecord(hwf_operrecord_info record);
	XINT  GetWFYXCommOperByYXRelative(XINT Type,WF_PARAM_COMM_OPRE_SIMPLE *&pwf_param_special_oper,XINT& nCount);

	XINT  WriteLink_Record(rWf_Link_Lock pRule);
	

	XINT  InsertLockAddtoDB(QString sIndexName,XINT LockAdd);

	//操作和提示短语
	XINT  GetSpecialPrompt(DATA_LINK db_link,XINT start_state,XINT end_state,rWf_SpecialPromptPhrase *&comm_prompt,XINT &count,XCHAR type);


	//获取五防专用操作短语(通过起始状态和结束状态)(只有一条)
	

	 XINT Construct_wf_warn_struct(Wf_OperRecord_Info &struct_wf,int MsgType,int operid ,QString sbak);
	


	//规则库
	XINT  DeleteRuleTable();
	XINT    GetWFYxCount_ByLockType(int type);
	XINT    ReadWfyxBy_DevType_grade(int devType,int grade,rWf_Yx_Info *&pwf_parem_yx,XINT &nCount);
	QString GetWFIndexNameByID(XINT ID);
	QString GetWFYCFullNameByIndexName(QString sIndexName);
	QString GetWFYXFullNameByIndexName(QString sIndexName);
	XINT    GetWFYXTypeByIndexName(QString sIndexName);

	XINT	  GetDeviceIDbyDeviceByName(XCHAR *szByName);
	XBYTE	  GetCurDeviceVoltageGradeByDevByName(char * szByName);
	XINT	  GetRutIDbyDeviceID(XINT DevID );
	XINT      GetWfSimpleYc_RelativeByIndexName(QString IndexName,WF_PARAM_YX_SIMPLE_RELATIVE &wf_parem_yx);
	XINT      GetWfSimpleYx_RelativeByIndexName(QString IndexName,WF_PARAM_YX_SIMPLE_RELATIVE &wf_parem_yx);
	XINT      GetALLWfSimpleYx_Relative(WF_PARAM_YX_SIMPLE_RELATIVE *&pwf_parem_yx,XINT &nCount);
	XINT      GetWfSimpleYx_Relative_Kg_WM(XINT 	WFType,WF_PARAM_YX_SIMPLE_RELATIVE &wf_parem_yx);
	XINT      GetYCUnitName(XCHAR *szByName,XINT ParentIndex,XCHAR* SUnit);

	QString GetoperateDsp(DATA_LINK db_link,XCHAR *szContent,XCHAR type,XCHAR *sVerb);

	//获取全厂规则库所有规则记录 
	XINT  GetALLRuleByRuleType(XINT Rule_type,rWf_Rule_Info*& pIndex,XINT& nCount);

	XINT  GetWFYCIndexNameandTypeByDevByNameAndindex(XCHAR *szByName,XINT ParentIndex,XCHAR *szIndexName);

	

	//根据数据关联结构获取YX记录
	XINT GetYxRecordByParentIDandIndex(XINT parentID,XINT index,rYxDefine_Info &yxrecord);
	XINT GetYcRecordByParentIDandIndex(XINT parentID,XINT index,rYcDefine_Info &ycrecord);


	//操作
	XINT GetHandSwitchOperType(XINT startstate,XINT endstate,QString &sOperType);
	XINT  GetHandSwitchAllstatebyopertype(XINT operType);
	 void GetPreandAfterstate(XINT ONorOFF,rWf_Rule_Info& pRule);
	 void GetExplainDsp(XINT ONorOFF,QString& sONorOFF);
	QString  GetVoltageGrade(XINT Grade);
	QString	GetWFErrorTypeDescripe(XBYTE wf_error_type);
	QString	GetWFOperTypeDescripe(int type);

	XINT fnWriteTicketStateandAccess(hwf_ticket_index_table ticket,XBYTE state,QString sAccess);

	//清空操作票表
	XINT fnGetWFDevMAXID( );
	XINT fnGetWFUnitMAXID();

	XINT	fnUpdateUnitNameByUnitID(XINT id,QString sNewName);
	XINT GetCurrentRelateState(DATA_LINK db_link);

	void    update_content_record(hwf_ticket_task_content task_content);//需要改字段
	XINT	fnSetWFTicketStateSucceedandTime(XINT ticket_id);
	XINT	fnUpdateTaskNameByTicketID(XINT ticket_id,QString sNewName,XBYTE DB_Type);

	//五防操作票库

	XINT	updateTicketstate_byid(XINT ticket_id,int state);
	XINT  fnRefreshWFTicketToFormal(XINT TicketID,QString sAssessorName,XINT Unit);
	XINT  fnModifyWFTicketUintByTicketID(XINT TicketID,XINT Unit);
	XINT	fnReadTicketByTime_createt_icket(hwf_ticket_index_table *&pTicketIndex,XINT &count,XINT TimeStart,XINT timeEnd);
	XINT	fnReadTicketByPiaoHao(hwf_ticket_index_table *&pTicketIndex,XINT &count,XINT piaohao);
	XINT	fnReadTicketALL(hwf_ticket_index_table *&pTicketIndex,XINT &count);
	XINT RecordWfOperateRecord(int start,int end,int OperID,hwf_operrecord_info *&pRecord,XINT &count);
	QString  GetTicketExe_state_his(XINT state);
	XINT	UpdateTicket_start_exe_time(hwf_ticket_index_table pTicketIndex);

	//地线操作相关函数
	XINT  SelectGroundLineByWFYX(XINT wfyxID);
	XINT  SelectUsableGroundLine(rWf_GroundWire_Info *&pGroundLine,XINT &count);
	XINT  bGetGroundLineVoltByID(XINT DXID);

    XINT  GetWf_LinkDistinct( WF_PARAM_YX_LINK_SIMPLE *&link,int &nCount);
	XINT  GetWf_Link_Record(DATA_LINK db_link,int oper,int attribute,rWf_Link_Lock *&pReturn,int &nCount);

	//操作票库相关
	
	XINT GetOperInfo(rOperator_Info *&device_name,XINT &nCount);
	XINT GetOperNameByOperID(XINT oper_id,QString& oper_name);
	XINT GetOperRecordByOperID(XINT oper_id,rOperator_Info &oper_record);
	XINT fnDeleteTicketContentByID(XINT ticket_id,XBYTE DB_Type);
	XINT WriteWf_para_record(rWf_Set_Para record);


	//数据关联
	XINT  GetCoulmnByTableID(XINT  TableID,STRUCT_COLUMN_SIMPLE_INFO*& pRet,XINT  &nCount);
	XINT GetCoulmnEnglishNameByCoulmnID(int tableID,XUINT coulmnID,QString& sColumnEngName);
	XINT   GetRWORKSTATIONInfoByDevID(rWorkStation_Unit*& pRet,XINT  &nCount);
	XINT   GetRFRONTSERVERInfoByDevID(rFrontServer_Unit*& pRet,XINT  &nCount);
	XINT   GetRFRONTROUTInfoByDevID(rFrontRout_Info*& pRet,XINT  &nCount);
	XINT GetTableEngNameByTableID(int tableID,QString &EngName);

	XINT  fnDeleteunitbyID(int unitid);
};

#endif // NSA3000TPFUN_H
